package com.liao.shapping;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.liao.shapping.activity.ShopActivity;
import com.liao.shapping.adapter.ItemListViewLayoutAdapter;
import com.liao.shapping.utils.ContentDatas;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView listView;
    private List<String> dailyKindList;
    private ItemListViewLayoutAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        initView();
    }

    private void initView() {
        listView = findViewById(R.id.listView);
        TextView tv_title = findViewById(R.id.tv_title);
        tv_title.setText("日常用品");
        dailyKindList = new ArrayList<>(ContentDatas.dailyKindList);
        adapter = new ItemListViewLayoutAdapter(this, dailyKindList);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(MainActivity.this, ShopActivity.class)
                        .putExtra("id", position)
                        .putExtra("title", dailyKindList.get(position)));
            }
        });
    }
}
